Going the Distance with Babylon.js by Josh Elster

Going the Distance with Babylon.js by Josh Elster

Author:Josh Elster
Language: eng
Format: epub, pdf
Publisher: Packt
Published: 2022-12-15T00:00:00+00:00


Figure 8.6 – The Alien.gltf model. The Scene Inspector window shows the __root__ transform node. From https://playground.babylonjs.com/#8IMNBM#1

The Alien geometry is what we’re interested in working with, but because it is parented to the __root__ node, any changes to the position, rotation, or scaling of Alien are evaluated in a coordinate space relative to that root node, resulting in undesired and unpredictable results. The solution to this is simple and answers our earlier question regarding what was up with our loadAssets code – unparent the desired mesh and dispose of the root. Once that’s accomplished, the rest of the code in our truck loading method is all housekeeping setup for the model – with some important considerations to keep in mind:

Order of operations is important, but not in the way you might think. Changes to a TransformNode (which Mesh is a descendent of) over a given frame are applied in the fixed order of Transform, Rotate, Scale (TRS).

Use setParent(null) rather than the alternative of setting mesh.parent = null. The setParent function preserves positional and rotational values, whereas setting the parent to null does not. This results in any root transformations being removed from the mesh, which is why we need to reset the position and rotation vectors.

Once the transformations have been cleared and the scaling has been set to world-appropriate values, the mesh geometry will need to have new bounding information generated. Otherwise, collisions won’t work properly. The solution to this is the two-step process of calling mesh.bakeCurrentTransformIntoVertices() before calling mesh.refreshBoundingInfo().



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.